home *** CD-ROM | disk | FTP | other *** search
/ Windows News 2010 Summer - Disc 1 / WN_Ete2010_CD1.iso / Onglet5 / Weezo / Weezo setup.exe / {code_appDir} / www / ext / download.php < prev    next >
PHP Script  |  2010-05-19  |  4KB  |  111 lines

  1. <?php
  2. /**
  3.  * Download a file
  4.  *
  5.  * URL format:
  6.  * RewriteRule ^(dl|downloads)\/dlToken([0-9]+)(\/resId[a-zA-Z0-9]+){0,1}\/(.+)  /ext/download.php?dlToken=$2&file=$4&resId=$3 [L]
  7.  * resId: resource id in current session, optional, skipped for direct downloads
  8.  * dlToken: id of current download, used for download resume. See efTokensWrite / efTokensRead functions.
  9.  *             When JS generated, concatenation of ascii values of path+filename chars
  10.  * file: rawurlencoded filename, including path
  11.  *
  12.  *
  13.  * PHP version 5
  14.  *
  15.  * LICENSE: This source file is subject to version 3.0 of the PHP license
  16.  * that is available through the world-wide-web at the following URI:
  17.  * http://www.php.net/license/3_0.txt.  If you did not receive a copy of
  18.  * the PHP License and are unable to obtain it through the web, please
  19.  * send a note to license@php.net so we can mail you a copy immediately.
  20.  *
  21.  * @category   NA
  22.  * @package    NA
  23.  * @author     Nicolas Bruley / Peer 2 World <contact@weezo.net>
  24.  * @copyright  2005-2009 Nicolas Bruley / Peer 2 World
  25.  * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
  26.  * @version    CVS: $Id:$
  27.  * @link       http://www.weezo.net
  28.  * @since      File available since Release 1.0.0
  29.  */
  30.  
  31.  
  32. /**
  33.  * @desc display error page
  34.  *
  35.  * @param integer $errorCode : HTTP error code
  36.  */
  37. function  displayError($errorCode){
  38.     require(INCLUDE_DIR.'initFunctions.php');
  39.     require(INCLUDE_DIR.'outputFunctions.php');
  40.  
  41.     switch ($errorCode){
  42.         case 403;
  43.             $message='403 Forbidden';
  44.             break;
  45.         case 404:
  46.         default:
  47.             $message='404 Not Found';
  48.             break;
  49.     }
  50.     header('HTTP/1.1 '.$message);
  51.     cfLog($message .' - '.$_SERVER["REQUEST_URI"],LOG_DBG);
  52.     wSession_write_close();
  53.     outDisplayErrorPage($message .' - '.$_SERVER["REQUEST_URI"]);
  54.     exit();
  55. }
  56. require(INCLUDE_DIR.'explorerFunctions.php');
  57. wSession_start();
  58.  
  59. $headers=getallheaders();
  60.  
  61. // Check IE download resume request
  62. if(isset($headers['If-Modified-Since']) && preg_replace('/;.*$/', '', $headers['If-Modified-Since'])){
  63.     header("HTTP/1.1 304 Not Modified");
  64.     if(!isset($_SESSION['userLogged'])) wSession_write_close();
  65.     exit;
  66. }
  67.  
  68. // Centralized authentication token existence check by central server
  69. if(isset($_GET['checkExistence'])){
  70.     // Get download token
  71.     if(!isset($_GET['dlToken'])) die();
  72.     $dlToken=$_GET['dlToken'];    if(substr($dlToken,0,7)=='dlToken') $dlToken=substr($dlToken,7);
  73.     // Load stored tokens and Check token existence
  74.     $tokenList=efTokensRead();
  75.     if(isset($tokenList[$dlToken])) die('ok'); else die('');
  76. }
  77.  
  78. // If no session, only rely on download token
  79. if(!isset($_SESSION['userLogged']) || strpos($_SERVER['REQUEST_URI'],'resId')===false) {
  80.     if(!isset($_SESSION['userLogged'])) wSession_destroy();
  81.     efResumeDownload($_GET['dlToken']);
  82.     exit;
  83. }
  84.  
  85. // Get file name
  86. $completeFilename=str_replace('*weezoPlus*','+',str_replace('*weezoSharp*','#',str_replace('&','&',str_replace('*weezoAmp*','&',str_replace('*weezoPercent*','%',$_GET['file'])))));
  87. $completeFilename=stripcslashes($completeFilename);
  88.  
  89. // Verify resource existence
  90. if(substr($_GET['resId'],0,6)=='/resId') $_GET['resId']=substr($_GET['resId'],6);
  91. if(!isset($_SESSION['res'][$_GET['resId']])) displayError(404);
  92.  
  93. // Switch to download's resource
  94. $_SESSION['activeResourceId']=$_GET['resId'];
  95.  
  96. // verify IP address
  97. if (!isset($_SESSION['userId']) || ($_SESSION['accountIP'] != $_SERVER['REMOTE_ADDR'] && cfGGetVar('disableClientSessionIPControl')!=true && !isset($_SERVER['HTTPS']))) displayError(403);
  98.  
  99. // verify that resource has a "path" property
  100. if(!cfRGetVar('path')) displayError(403);
  101.  
  102. // Inject data into POST
  103. $_POST['data1']=cfDirName(stripslashes($completeFilename));
  104. $_POST['data2']=basename($completeFilename);
  105. $_POST['data3']='download';
  106. $_POST['data5']=$_GET['dlToken'];
  107. $_GET ['data5']='dlToken'.$_GET['dlToken'];
  108.  
  109. // Proceed to POST processing
  110. efProcessPOST();
  111. ?>